/* WebROaR - Ruby Application Server - http://webroar.in/
 * Copyright (C) 2009  Goonj LLC
 *
 * This file is part of WebROaR.
 *
 * WebROaR is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebROaR is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebROaR.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef WR_CONNECTION_H_
#define WR_CONNECTION_H_

#include <wr_controller.h>

/** Connection */

typedef struct {
  wr_u_int      id;          /* Connection id */
  ebb_connection   *ebb_conn;  /* EBB connection */
  int           resp_to_write;  /* Number of bytes to be written*/
  wr_svr_t      *svr;        /* Pointer to wr_svr_t */
  wr_req_t      *req;      /* Pointer to wr_req_t */

  short       is_closed;          /* Connection state flag */
  short       keep_alive;    /**< HTTP connection keep alive state flag */
  wr_str_list_t  *resp;
}wr_conn_t;

/** Destroy Connection */
void wr_conn_free(wr_conn_t*);
/** Add response to Connection */
int wr_conn_resp_body_add(wr_conn_t*, const char*, size_t);
/** New connection call back
 * Allocates and initializes an ebb_connection.  NULL by default. */
ebb_connection* wr_new_conn_cb(ebb_server*, struct sockaddr_in*);

/************************/

/************** Errorneous response rendering API ***************/
/** Response Status Code **/
typedef enum {
  WR_HTTP_STATUS_100 = 0 ,  
  WR_HTTP_STATUS_400 ,
  WR_HTTP_STATUS_403 ,
  WR_HTTP_STATUS_404 ,  
  WR_HTTP_STATUS_405 ,
  WR_HTTP_STATUS_411 ,
  WR_HTTP_STATUS_413 ,
  WR_HTTP_STATUS_414 ,
  WR_HTTP_STATUS_500 ,
  WR_HTTP_STATUS_501 ,
  WR_HTTP_STATUS_503
}wr_resp_status_t;

/** Response generated by Server */
void wr_conn_err_resp(wr_conn_t *, wr_resp_status_t);


#endif /*WR_CONNECTION_H_*/
